package cn.edu.jmu.oelp.service.impl;

import cn.edu.jmu.oelp.mapper.ParagraphsMapper;
import cn.edu.jmu.oelp.pojo.Article;
import cn.edu.jmu.oelp.pojo.Paragraphs;
import cn.edu.jmu.oelp.utils.SplitContentUtils;
import cn.edu.jmu.oelp.service.ParagraphsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wen
 */
@Service
public class ParagraphsServiceImpl implements ParagraphsService {

    @Autowired
    ParagraphsMapper paragraphsMapper;

    @Override
    public boolean splitArticle(Article article) {
        String content = article.getContent();
        SplitContentUtils splitContentUtils = new SplitContentUtils(content);
        List<String> contentList = splitContentUtils.getList();
        for (String s : contentList) {
            Paragraphs paragraphs = new Paragraphs();
            paragraphs.setContent(s);
            paragraphs.setArticleId(article.getId());
            addParagraphs(paragraphs);
        }

        return true;
    }

    @Override
    public boolean addParagraphs(Paragraphs paragraphs) {
        return paragraphsMapper.insertParagraphs(paragraphs);
    }

    @Override
    public boolean deleteParagraphs(int id) {
        return paragraphsMapper.delParagraphs(id);
    }

    @Override
    public boolean updateParagraphs(Paragraphs paragraphs) {
        return paragraphsMapper.updateParagraphs(paragraphs);
    }

    @Override
    public Paragraphs findById(int id) {
        return paragraphsMapper.findParagraphsById(id);
    }

    @Override
    public List<Paragraphs> findByArticleId(int articleId) {
        return paragraphsMapper.findParagraphsByArticleId(articleId);
    }

    @Override
    public List<Paragraphs> findAll() {
        return paragraphsMapper.findAll();
    }

    @Override
    public Paragraphs findUserNextParagraphs(int id) {
        return paragraphsMapper.findUserParagraphs(id);
    }

    @Override
    public Paragraphs findUserBackParagraphs(int id) {
        return paragraphsMapper.findBackParagraphs(id);
    }
}
